package cn.com.wxd.util.user;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.com.wxd.entity.user.AccountInfo;
import cn.com.wxd.service.user.UserCore;
import cn.com.wxd.util.service.ProjectInfo;

/**
 * Title:UserCoreUtil.java
 * Description:cn.com.wxd.util
 * <p>
 * Company: Amumu管理平台
 * Copyright: Copyright (c) 2015
 * All right reserved.
 * Created time: 2016-9-2 下午3:14:52
 *
 * @author WangXuDong
 * @version 1.0
 */
public class UserCoreUtil {

    private static final Logger log = LoggerFactory.getLogger(UserCoreUtil.class);

    private static UserCore userCore = new UserCore();

    /**
     * 获取目前登录的账号信息
     *
     * @param request
     *
     * @return
     */
    public static AccountInfo getLoginAccount(HttpServletRequest request) {
        return userCore.getLoginAccount(request.getSession());
    }

    /**
     * 添加登录用户信息
     *
     * @param request
     * @param accountInfo
     *
     * @return
     */
    public static AccountInfo setLoginUser(HttpServletRequest request, AccountInfo accountInfo) {
        return userCore.setLoginUser(request.getSession(), accountInfo, ProjectInfo.isRememberUser());
    }

    /**
     * 添加登录用户信息
     *
     * @param request
     * @param accountInfo
     * @param isRememberPwd 是否记住密码
     *
     * @return
     */
    public static AccountInfo setLoginUser(HttpServletRequest request, AccountInfo accountInfo
            , boolean isRememberPwd) {
        return userCore.setLoginUser(request.getSession(), accountInfo, isRememberPwd);
    }

    /**
     * 注销当前登录的用户
     *
     * @param request
     */
    public static void logoutUser(HttpServletRequest request) {
        userCore.logoutUser(request.getSession());
    }
}
